//
//  LGTabBarViewController.m
//  Eluxiao
//
//  Created by Chen on 16/8/19.
//  Copyright © 2016年 langan. All rights reserved.
//

#import "LGTabBarViewController.h"
#import "LGNavigationController.h"
//患者管理
#import "LGPatientViewController.h"
//咨询管理
#import "LGConsultHomeController.h"
//我的
#import "LGMineViewController.h"

@interface UIImage (Extension)
// 快速的返回一个最原始的图片
+ (instancetype)imageWithOriRenderingImage:(NSString *)imageName;
@end

@interface LGTabBarViewController ()<UITabBarControllerDelegate>

@end

@implementation LGTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    [UITabBar appearance].translucent = NO;
    //默认颜色、字体
    [[UITabBarItem appearance]setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithString:@"171417"],NSForegroundColorAttributeName,[UIFont systemFontOfSize:11],NSFontAttributeName,nil]forState:UIControlStateNormal];
    //选中颜色、字体
    [[UITabBarItem appearance]setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithString:kThemeColor],NSForegroundColorAttributeName,[UIFont systemFontOfSize:11],NSFontAttributeName,nil]forState:UIControlStateSelected];
    //iOS 13  文字颜色变蓝色
    [[UITabBar appearance] setTintColor:[UIColor colorWithString:@"02BE61"]];
    [[UITabBar appearance] setUnselectedItemTintColor:[UIColor colorWithString:@"171417"]];
    

    //患者管理
    [self addOneViewController:[[LGPatientViewController alloc]init] image:@"patientNormal" selectedImage:@"patientSelect" title:@"患者管理"];
    //咨询管理
    [self addOneViewController:[[LGConsultHomeController alloc] init] image:@"newsNormal" selectedImage:@"newsSelect" title:@"咨询管理"];
    //我的
    [self addOneViewController:[[LGMineViewController alloc]init] image:@"mineNormal" selectedImage:@"mineSelect" title:@"我的"];
}


- (void)addOneViewController:(UIViewController *)childViewController image:(NSString *)imageName selectedImage:(NSString *)selectedImageName title:(NSString *)title{
    LGNavigationController *nav = [[LGNavigationController alloc] initWithRootViewController:childViewController];
    //设置图片和文字之间的间距
    nav.tabBarItem.imageInsets = UIEdgeInsetsMake(-2, 0, 2, 0);
    nav.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -4);
    
    //设置tabBar文字
    nav.tabBarItem.title = title;
    //设置正常状态下的图标
    nav.tabBarItem.image = [UIImage imageWithOriRenderingImage:imageName];
    //设置选中状态下的图标
    nav.tabBarItem.selectedImage = [UIImage imageWithOriRenderingImage:selectedImageName];
    //添加tabBar为控制器的子控制器
    [self addChildViewController:nav];
}


- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    UINavigationController *nav = self.selectedViewController;
//    UIViewController *controller = nav.viewControllers[0];
    
}

- (BOOL)shouldAutorotate {
    
    return [self.selectedViewController shouldAutorotate];
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    
    return [self.selectedViewController supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    
    return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}


@end



@implementation UIImage (Extension)

// 快速的返回一个最原始的图片
+ (instancetype)imageWithOriRenderingImage:(NSString *)imageName {
    UIImage *image = [UIImage imageNamed:imageName];
    return [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

@end


